package cn.wolfcode.luowowo.mgrsite.controller;

import cn.wolfcode.luowowo.acticle.domain.StrategyCommend;
import cn.wolfcode.luowowo.acticle.domain.StrategyDetail;
import cn.wolfcode.luowowo.acticle.query.StrategyCommendQueryObject;
import cn.wolfcode.luowowo.acticle.service.IStrategyCommendService;
import cn.wolfcode.luowowo.acticle.service.IStrategyDetailService;
import cn.wolfcode.luowowo.acticle.service.IStrategyService;
import cn.wolfcode.luowowo.common.util.AjaxResult;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 攻略推荐资源管理器
 */
@Controller
@RequestMapping("/strategyCommend")
public class StrategyCommendController {
    @Reference
    private IStrategyCommendService strategyCommendService;
    @Reference
    private IStrategyService strategyService;
    @Reference
    private IStrategyDetailService strategyDetailService;

    //大攻略推荐列表
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") StrategyCommendQueryObject qo){
        PageInfo pageInfo = strategyCommendService .query(qo);
        model.addAttribute("pageInfo", pageInfo);
        //strategies
        model.addAttribute("strategies", strategyService.listAll());
        return "strategyCommend/list";
    }
    
    //保存攻略推荐
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(StrategyCommend strategyCommend){
        strategyCommendService.saveOrUpdate(strategyCommend);
        return new AjaxResult();
    }
    //删除攻略推荐
    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(Long id){
        strategyCommendService.delete(id);
        return new AjaxResult();
    }

    //根据攻略id查询明细
    @RequestMapping("/getDetailByStrategyId")
    @ResponseBody
    public Object getDetailByStrategyId(Long strategyId){
        List<StrategyDetail> list = strategyDetailService.getDetailByStrategyId(strategyId);
        return list;
    }
}
